package Persistencia.DAO;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;

import models.Cliente;
import play.db.jpa.JPA;
import play.mvc.Scope.Params;
import Persistencia.Exception.DAOException;

public class DAOCliente implements IDAOCliente{

	@Override
	public void addEntity(Cliente entity) throws DAOException {
		EntityManager em = JPA.em();
		em.persist(entity);
		//entity.create();		
	}

	@Override
	public void updateEntity(Cliente entity) throws DAOException {
		// TODO Auto-generated method stub
		EntityManager em = JPA.em();
		entity.merge();
		em.flush();
	}

	@Override
	public void removeEntity(Cliente entity) throws DAOException {
		EntityManager em = JPA.em();
		entity.delete();
	}

	@Override
	public List<Cliente> findAll() throws DAOException {
		List<Cliente> c = Cliente.findAll();
		return c;
	}

	@Override
	public Cliente findById(Integer id) throws DAOException {
		// TODO Auto-generated method stub
		EntityManager em = JPA.em();
		Cliente c = (Cliente) em.createQuery("SELECT * FROM cliente c WHERE c.id=:id").setParameter(":id", id).getSingleResult();
		return c;
	}

		
	
}
